﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using Alos.Common;
using Alos.Entity;
using Alos.IService;
using System.Threading.Tasks;
using System.Configuration;

namespace Alos.LanClass.Api
{
    /// <summary>
    /// 发布记录表
    /// </summary>
    public class ReArrangeRecordController : ApiController
    {
        IReArrangeRecordService ReArrangeRecordService;
        
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="_IReArrangeRecordService"></param>       
        public ReArrangeRecordController(IReArrangeRecordService _IReArrangeRecordService)
        {
            ReArrangeRecordService = _IReArrangeRecordService;           
        }
        /// <summary>
        /// 添加发布记录(点击推送)-如果为任务单的时候调用
        /// <param name="reArrangeRecord">ClassID-LessonID-ResourceID</param>
        /// <returns></returns>
        /// </summary>
        [HttpPost]
        [Route("api/ReArrangeRecord/StartReArrangeRecord")]
        public JsonRtn<dynamic> StartReArrangeRecord([FromBody]ReArrangeRecord reArrangeRecord)
        {
            var jsRtn = new JsonRtn<dynamic>();
            reArrangeRecord.ID = System.Guid.NewGuid();
            string serviceIP = ConfigurationManager.AppSettings["ServerIP"];
            jsRtn.message = ReArrangeRecordService.CreateReArrangeRecord(reArrangeRecord,serviceIP).ToString();
            jsRtn.data = reArrangeRecord.ID;
            return jsRtn;
        }
        /// <summary>
        /// 根据ID修改发布记录状态
        /// <param name="id"></param>
        /// <returns></returns>
        /// </summary>
        [HttpPost]
        [Route("api/ReArrangeRecord/UpdateReArrangeRecord")]
        public JsonRtn<dynamic> UpdateReArrangeRecord([FromBody]int id)
        {
            var jsRtn = new JsonRtn<dynamic>();
            jsRtn.message = ReArrangeRecordService.UpdateReArrangeRecord(id).ToString();          
            return jsRtn;
        }
       
    }
}
